//
//  CustomWindow.m
//  DEMO
//
//  Created by J on 16/2/20.
//  Copyright © 2016年 J. All rights reserved.
//

#import "CustomWindow.h"
#import "BrownView.h"
@implementation CustomWindow

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
   BOOL is =  [super pointInside:point withEvent:event];
    NSLog(@" %s %zd",__FUNCTION__,is);

    return is;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    //1.判断当前控件能否接收事件
    if(self.userInteractionEnabled==NO||self.hidden==YES||self.alpha<0.01)return nil;
    
    //2.判断点在不在当前控件
    if([self pointInside:point withEvent:event]==NO) return nil;
    
    //3.从后往前遍历自己的子控件
    NSUInteger count = self.subviews.count;
    
    for (NSUInteger i=0; i<count; i++) {
        UIView* childView = self.subviews[i];
        
        //把当前控件上的坐标系转换成子控件上的坐标系
        CGPoint childPoint = [self convertPoint:point toView:childView];
        UIView* fitView = [childView hitTest:childPoint withEvent:event];
        if(fitView){//找到最合适的View
            return childView;
        }
    }
        return self;
}




@end
